package com.baidu.videoseries.util;

import android.animation.ValueAnimator;
import android.view.View;

import com.kvin.toolkit.utils.LogUtils;

/**
 * Created by leiyun on 2018/5/15.
 */
public class AnimHelper {

    private View mView;
    private final ValueAnimator mAnimator;

    private AnimHelper() {
        mAnimator = ValueAnimator.ofFloat(1.0f, 0.5f, 1.0f);
    }

    /**
     * constructor
     */
    public static AnimHelper getInstance() {
        return new AnimHelper();
    }

    /**
     * start anim
     */
    public void startAnim(View v, long du) {
        this.mView = v;
        this.mAnimator.setDuration(du < 1 ? 1000 : du);
        this.mAnimator.addUpdateListener(new AnimUpdateHandle());
        this.mAnimator.start();
    }


    /**
     * anim update ck
     */
    class AnimUpdateHandle implements ValueAnimator.AnimatorUpdateListener {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float scaleFactor = (float) animation.getAnimatedValue();//get calculated value
            mView.setScaleX(scaleFactor);
            mView.setScaleY(scaleFactor);
            LogUtils.d("-----" + animation.getAnimatedValue());
        }
    }
}
